package com.字符流;

import java.io.*;

/*两个桥梁
InputStreamReader: 字节流---字符流
OutputStreamWriter: 字符流---字节流
* */
public class ConversionStreamDemo {
    public static void main(String[] args) throws IOException {
        //默认字符集
//        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("idea_test\\a.txt"));
        //指定字符集
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("idea_test\\a.txt"), "GBK");
        osw.write("中国");
        osw.close();

        //默认字符集
//        InputStreamReader isr = new InputStreamReader(new FileInputStream("idea_test\\a.txt"));
        //指定字符集
        InputStreamReader isr = new InputStreamReader(new FileInputStream("idea_test\\a.txt"),"GBk");
        //一次读一个字符数据
        int ch;
        while ((ch = isr.read()) != -1) {
            System.out.print((char) ch);
        }
        //释放资源
        isr.close();
    }
}
